package com.csnf.product.controller;

import com.csnf.pojo.Product;
import com.csnf.product.service.ProductService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    ProductService productService;

    //根据商品编号查询商品信息
    @RequestMapping("/getProductById")
    public Product getProductById(Integer id, HttpServletRequest request){
        //获取token
        String token = request.getHeader("token");
        System.out.println("====商品服务中接收到的token ===="+token);

        //休眠2秒
//        try {
//            //Thread.sleep(2000);  //毫秒
//            TimeUnit.SECONDS.sleep(2); //秒
//
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }

//        //手动制造一个错误
//        int r = 3/0;




        Product product  = productService.getProductById(id);

        return product;
    }




}
